package logic

import (
	"baidu/baidurpc/baidurpc"
	"context"

	"baidu/api/internal/svc"
	"baidu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ForgetPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewForgetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgetPasswordLogic {
	return &ForgetPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ForgetPasswordLogic) ForgetPassword(req *types.ForgetPasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	password, err := l.svcCtx.BaiDuRpc.ForgetPassword(l.ctx, &baidurpc.ForgetPasswordRequest{
		UserId:      req.UserId,
		Password:    req.Password,
		Mobile:      req.Mobile,
		NewPassword: req.NewPassword,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "找回密码成功",
		Data:    password,
		Code:    200,
	}, nil
}
